#include "mainwindow.h"
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include <QDialog>
#include <QDebug>
#include <QMessageBox>
#include <QFileDialog>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    QMenuBar *mbar = menuBar();
    setMenuBar(mbar);
    QMenu *menu = mbar->addMenu("对话框");
    QAction *p1 = menu->addAction("模态对话框");
    connect(p1, &QAction::triggered,
            []
            ()
    {
        QDialog dlg;
        dlg.exec();
        qDebug() << "模态对话框退出";
    });

    QAction *p2 = menu->addAction("非模态对话框");
    connect(p2, &QAction::triggered,
            [=]
            ()
    {
        QDialog *p = new QDialog();
        p->setAttribute(Qt::WA_DeleteOnClose);
        p->show();
        qDebug() << "模态对话框退出";
    });

    QAction *p3 = menu->addAction("关于对话框");
    connect(p3, &QAction::triggered,
            [=]
            ()
    {
        QMessageBox::about(this, "about", "关于qt");
    });

    QAction *p4 = menu->addAction("问题对话框");
    connect(p4, &QAction::triggered,
            [=]
            ()
    {
        int ret = QMessageBox::question(this, "question", "Are you ok ?");
        switch (ret) {
        case QMessageBox::Yes:
        {
            qDebug() << "you clike the yes btn";
            break;
        }
        case QMessageBox::No:
        {
            qDebug() << "you clike the no btn";
            break;
        }
        }
    });

    QAction *p5 = menu->addAction("文件对话框");
    connect(p5, &QAction::triggered,
            [=]
            ()
        {
            QString path = QFileDialog::getOpenFileName(this,
                                                        "open",
                                                        "../",
                                                        "source(*.cpp *.h)"
                                                        ";;all(*.*)");
            qDebug() << path;
        });
}

MainWindow::~MainWindow()
{
}

